package models;

import java.sql.Date;
import java.util.List;
import javax.persistence.*;
import play.db.ebean.Model;


@Entity
@Table(name = "article")
public class Article extends Model {
        
    @Id
    public Long id_article;
    public String libelle_article;
    public String description_article;
    public double prix_article;
    public Integer qte_article;
    public Integer etat_article;
    public Date date_disponibilite_article;
    @ManyToOne
    public Categorie category;
    @OneToMany
    public List<LigneCommande> lignesCommande;
    @ManyToOne
    public Proposition proposition;
    
    public static Finder<Long,Article> find = new Finder<Long,Article>(Long.class, Article.class); 
    
    public static List<Article> listeArticles() {
    return find.all();
    }
    
    public static void create(Article article) {
            article.save();
    }

    public static void delete(Long id_article) {
            find.ref(id_article).delete();
    }
    
    public void ajouterArticleAPanier(LigneCommande ligneCommande) {
        lignesCommande.add(ligneCommande);
        }
    
    public static Article findById(Long id) {
        return find.where().eq("id_article", id).findUnique();
}

}